<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>

        /* let arr = [1, 1, 2, 2, 3, 3, 4, 5, 5, 5, 6, 3, 2, 4, 5, 2, 4, 2, 2, 4, 5, 6, 6,]
        // 1.创建一个空对象
        let obj = {};
        // 2.循环数组中的每一项，把每一项对象进行储存 = 》 item: item;
        for (let i = 0; i < arr.length; i++) {
            let item = arr[i];
            // 3.每一次储存之前进行判断：验证obj中是否存在这一项
            if (obj[item] !== undefined) {
                arr.splice(i, 1)
                i--;
                continue;
            }
            obj[item] = item;
        }
        console.log(arr); */

        // ==========================
        /* let arr = [1, 1, 2, 2, 3, 3, 4, 5, 5, 5, 6, 3, 2, 4, 5, 2, 4, 2, 2, 4, 5, 6, 6,]
        let obj = {};
        for (let i = 0; i < arr.length; i++) {
            let item = arr[i];
            if (obj[item] === item) {
                arr.splice(i, 1);
                i--;
                continue;
            }
            obj[item] = item;
        }
        console.log(arr); */

        // ==========================
        /* let arr = [1, 1, 2, 2, 3, 3, 4, 5, 5, 5, 6, 3, 2, 4, 5, 2, 4, 2, 2, 4, 5, 6, 6,]
        let obj = {};
        for (let i = 0; i < arr.length; i++) {
            let item = arr[i];
            if (obj[item] !== undefined) {
                arr[i] = arr[arr.length - 1];
                arr.length--;
                i--;
                continue;
            }
            obj[item] = item;
        }
        console.log(arr); */

        /* // ========================== 封装数组去重
        let arr = [1, 1, 2, 2, 3, 3, 4, 5, 5, 5, 6, 3, 2, 4, 5, 2, 4, 2, 2, 4, 5, 6, 6,]
        let unique = (arr) => {
            let obj = {};
            for (let i = 0; i < arr.length; i++) {
                let item = arr[i]
                if (obj[item] !== undefined) {
                    arr[i] = arr[arr.length - 1];
                    arr.length--;
                    i--;
                    continue;
                }
                obj[item] = item;
            };
            return arr;
        }
        console.log(unique(arr)); */

        // ========================== Set数组去重
        let arr = [1, 1, 2, 2, 3, 3, 4, 5, 5, 5, 6, 3, 2, 4, 5, 2, 4, 2, 2, 4, 5, 6, 6,]
        ary = [... new Set(arr)]
        console.log(ary);

        // ========================== Set数组去重




    </script>
</body>

</html>